package cn.kgc.springboot02.service.impl;

import cn.kgc.springboot02.entity.Student;
import cn.kgc.springboot02.mapper.StudentMapper;
import cn.kgc.springboot02.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/7/19
 * @Description:
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> getList() {

        return studentMapper.getList();
    }

    @Override
    public Map<String,Object> getPage(Integer page, Integer limit) {

        PageHelper.startPage(page,limit);
        List<Student> list = studentMapper.getList();
        PageInfo<Student> studentPageInfo = new PageInfo<>(list);

        HashMap<String, Object> map = new HashMap<>();
        map.put("code",200);
        map.put("data",studentPageInfo.getList());
        map.put("count",studentPageInfo.getTotal());
        return map;

    }
}
